<?php
/*********************/
/*                   */
/*  Version : 5.1.0  */
/*  Author  : RM     */
/*  Comment : 071223 */
/*                   */
/*********************/

class BaseInitialize extends Base
{

	public $_errorlevel = 7;
	public $_charset = "UTF-8";
	public $_contenttype = "text/html";
	public $_systeminfo = array( );
	public $_configinfo = array( );
	public $refer_url = "";
	public $cur_url = "";
	public $agent_ip = "";
	public $session_expire_time = 600;
	public $cookie_expire_time = 36000000;
	public $cookie_back_form = array( );
	public $_input = array( );
	public $session_id = "";
	public $check_powerby = true;
	public $obj_ini_cache = NULL;
	public $_websitconfig = array( );
	public $_dbconfig = array( );
	public $_fileconfig = array( );
	public $date_default_timezone = "Asia/Shanghai";
	public $_umask = 18;

	public function _initialize( )
	{
		error_reporting( $this->_errorlevel );
		define( "Base_Use_Sign", true );
		ini_set( "allow_url_fopen", "1" );
		if ( function_exists( "date_default_timezone_set" ) )
		{
			date_default_timezone_set( $this->date_default_timezone );
		}
		umask( $this->_umask );
		$this->_getObjCache( );
		$this->_getConfiginfo( );
		$this->_getSysVersion( );
		if ( function_exists( "ob_gzhandler" ) && $this->_configinfo['websit']['gzip'] == 1 )
		{
			@ob_start( "ob_gzhandler" );
		}
		else
		{
			@ob_start( );
		}
		if ( 0 < intval( $this->_configinfo['cookie']['session_expire'] ) )
		{
			$this->session_expire_time = intval( $this->_configinfo['cookie']['session_expire'] );
			session_set_cookie_params( $this->session_expire_time * 60, $this->_configinfo['cookie']['cookiepath'], $this->_configinfo['cookie']['cookiedomain'] );
		}
		if ( $_SESSION['s_login']['login'] == "" && $_COOKIE['c_session_id'] != "" )
		{
			session_id( $_COOKIE['c_session_id'] );
			@session_start( );
		}
		else
		{
			@session_start( );
		}
		if ( 0 < intval( $this->_configinfo['cookie']['cookie_expire'] ) )
		{
			$this->cookie_expire_time = intval( $this->_configinfo['cookie']['cookie_expire'] );
		}
		$this->_charset = $this->_configinfo['websit']['ncharset'] ? strtoupper( $this->_configinfo['websit']['ncharset'] ) : $this->_charset;
		@header( "Content-type: ".$this->_contenttype."; charset=".$this->_charset );
		$this->_setincludepage( );
		if ( array_key_exists( "HTTP_REFERER", $_SERVER ) )
		{
			$this->refer_url = $_SERVER['HTTP_REFERER'];
		}
		else
		{
			$this->refer_url = "";
		}
		$this->cur_url = Common::getcurrurl( );
		$this->agent_ip = $_SERVER['REMOTE_ADDR'];
		$this->request_uri( );
		$this->_getparam( );
		$this->cookie_back_form = $this->getCookies( "back" );
	}

	public function _getconfigini( $_fileName, $_defaultCharset = "UTF-8" )
	{
		$this->_getObjCache( );
		$this->obj_ini_cache->OperateCacheFile( $_fileName, "ini", $_defaultCharset );
		return $this->obj_ini_cache->cache_array;
	}

	public function _setincludepage( )
	{
		$_os = substr( PHP_OS, 0, 3 ) == "WIN" ? ";" : ":";
		$_includepathArray = explode( ",", $this->_systeminfo['global']['includepath'] );
		$_path = ".";
		foreach ( $_includepathArray as $_value => $_includepath)
		{
			$_path .= $_os.BasePath."/".$_includepath;
		}
		ini_set( "include_path", $_path );
	}

	public function _getparam( )
	{
		$this->_input = !empty( $_GET ) ? Common::input_addslashes_for_get_array( $_GET ) : array( );
		$this->_input = !empty( $_POST ) ? array_merge( $this->_input, Common::input_addslashes_array( $_POST ) ) : $this->_input;
		$GLOBALS['_COOKIE'] = Common::input_addslashes_array( $_COOKIE );
	}

	public function setCookies( $_cookieKey, $_cookie_pcode, $_cookie_expire_time = 36000000 )
	{
		setcookie( $this->_configinfo['cookie']['cookiepre'].$_cookieKey, $_cookie_pcode, $_cookie_expire_time ? time( ) + $_cookie_expire_time : 0, $this->_configinfo['cookie']['cookiepath'], $this->_configinfo['cookie']['cookiedomain'], $_SERVER['SERVER_PORT'] == 443 ? 1 : 0 );
	}

	public function getCookies( $_cookieKey )
	{
		return $_COOKIE[$this->_configinfo['cookie']['cookiepre'].$_cookieKey];
	}

	public function request_uri( )
	{
		if ( isset( $_SERVER['REQUEST_URI'] ) )
		{
			return true;
		}
		if ( isset( $_SERVER['argv'] ) )
		{
			$GLOBALS['_SERVER']['REQUEST_URI'] = $_SERVER['PHP_SELF']."?".$_SERVER['argv'][0];
		}
		else
		{
			$GLOBALS['_SERVER']['REQUEST_URI'] = $_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING'];
		}
		return true;
	}

	public function _getConfiginfo( )
	{
		$this->_configinfo = $this->_getconfigini( "config.ini.php" );
		$this->_systeminfo = $this->_getconfigini( "system.ini.php", $this->_charset );
		$this->_websitconfig = $this->_configinfo['websit'];
		$GLOBALS['GLOBALS']['dbconfig'] = $this->_dbconfig = $this->_configinfo['database'];
		$this->_fileconfig = $this->_configinfo['file'];
	}

	public function _getSysVersion( )
	{
		$this->_systeminfo['version']['project'] = "LuckyTao Multishop";
		$this->_systeminfo['version']['revision'] = "v1.0";
		$this->_systeminfo['version']['type'] = " ";
		$this->_systeminfo['version']['domain'] = array( "127.0.0.1", "localhost" );
		$this->_systeminfo['version']['version'] = $this->_systeminfo['version']['project']." ".$this->_systeminfo['version']['revision']." ".$this->_systeminfo['version']['type'];
	}

	public function _getObjCache( )
	{
		if ( !is_object( $this->obj_ini_cache ) )
		{
			$this->obj_ini_cache = new OperateCache( );
		}
	}

}

?>
